package dse.messages.singleversion;

import dse.DataObject;
import dse.Experiment;
import dse.ExperimentRecorder;
import dse.messages.Message;
import dse.messages.MessageHandler;
import dse.messages.MessageSender;
import dse.messages.MessageType;

public class ShareUpdateV6ResponseMessageHandler extends MessageSender
		implements MessageHandler {

	private int shareIndex;
	private DataObject dobj;
	private ShareDownloader downloader;
	
	public ShareUpdateV6ResponseMessageHandler(Experiment experiment, DataObject dobj, int index, ShareDownloader downloader)
	{
		super(experiment);
		this.dobj = dobj;
		this.shareIndex = index;
		this.downloader = downloader;
	}
	
	@Override
	public boolean acceptMessage(Message message) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void messageInterupted(ExperimentRecorder recorder, Message message,
			double time) {
		// TODO Auto-generated method stub
		//recorder.debug(this, "msgIntrpt: " + message, time);
		downloader.shareUpdateFailed(recorder, dobj, 0, time);
	}

	@Override
	public void messageReceived(ExperimentRecorder recorder, Message message,
			double time) {
		// TODO Auto-generated method stub
		//recorder.debug(this, "msgRcvd: " + message, time);
		if (message.messageType() != MessageType.ShareUpdateV6Response) {
			recorder.warn(
					"ShareUpdateV6ResponseMessageHandler recieved " + 
					message.messageType() + " message."
					);
			return;
		}
			
		downloader.shareUpdated(recorder, message.from(), dobj, shareIndex, time);
	}


}
